/**
 * 展示报表相关JS
 */
$(function () {
    // 初始化多选下拉框
    $('.multiSelect').fSelect();

    var column = eval('(' + columns + ')');  // 将字符串转换成JSON(列信息)
    var lockColumn = eval('(' + lockColumns + ')');  // 将字符串转换成JSON(冻结列信息)
    var thirdParam = eval('(' + thirdParams + ')');  // 将字符串转换成JSON(第三方系统传入参数)
    var initCondition = $("#initCondition").val();  // 将字符串转换成JSON(报表初始化参数)
    var conditionJson = eval('(' + initCondition + ')');
    var pagination = false;
    if(isPage == '1') {  // 判断报表是否需要分页
        pagination = true;
    }

    // 初始化外部系统传入的参数
    $.each(thirdParam, function (index, obj) {
        var paramName = obj.paramName;
        var paramValue = obj.paramValue;
        var input = $("<input>");
        input.attr("type", "hidden");
        input.attr("name", paramName);
        input.attr("id", paramName);
        input.attr("value", paramValue);
        $("#tb").append(input);
    });

    // 查询参数
    var param = {};
    var queryURL = "";
    $.each(conditionJson, function(index, content){
        queryURL = basePath + "/rptTools/showRpt/queryRptInfo";
        var paramName = content.paramName;
        var paramValue = content.paramValue;
        param[paramName] = paramValue;
    });
    if(isDrill == '1' && queryURL == "") {
        queryURL = basePath + "/rptTools/showRpt/queryRptInfo";
    }
    if(queryURL != "") {
        var rptId = $('#rptId').val();
        param.rptId = rptId;

        // 获取选中的指标
        var idx_array=new Array();
        $('input[name="rptIdx"]:checked').each(function(){
            idx_array.push($(this).val());//向数组中添加元素
        });
        var rptIdx=idx_array.join(',');//将数组元素连接起来以构建一个字符串

        // 获取选中的维度
        var dim_array=new Array();
        $('input[name="rptDim"]:checked').each(function(){
            dim_array.push($(this).val());//向数组中添加元素
        });
        var rptDim=dim_array.join(',');//将数组元素连接起来以构建一个字符串

        var dimNum = dim_array.length;
        if(dimNum > 0) {  // 根据选择的指标重置表头信息
            param.rptIdx = rptIdx;
            param.rptDim = rptDim;
            var dynamicFormate = $("#formatType").val();
            $.ajax({
                url:basePath + "/rptTools/showRpt/resetRptHeader",
                type: "POST",
                async : false,
                dataType : "json",
                data:{
                    rptId: rptId,
                    rptIdx: rptIdx,
                    rptDim: rptDim,
                    dynamicFormate: dynamicFormate
                },
                success:function(data){  // 重置表头成功后查询报表数据
                    column = eval('(' + data.tableHeader + ')');  // 将字符串转换成JSON(列信息)
                }
            });
        }

        // 刷新下钻报表
        $.ajax({
            url:basePath + "/rptTools/rptMgr/refreshCacheById",
            type: "POST",
            async : false,
            dataType : "json",
            data:{
                rptId: rptId
            },
            success:function(data){  // 重置表头成功后查询报表数据

            }
        });

        // 获取页面查询条件
        var conditionCol = $("#conditionCol").val();
        var condition = eval('(' + conditionCol + ')');

        // 获取查询条件的值
        $.each(condition, function(index, content){
            var field = content.aliasField;
            var conditionType = content.conditionType;
            if(conditionType == '4') {  // 如果查询类型为日期区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else if(conditionType == '5') {  // 如果查询类型为树
                var hidField = "hid_" + field;
                var fieldValue = $("#" + hidField).val();

                param[hidField] = fieldValue;
            } else if (conditionType == '6') {  // 如果查询类型为值区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else {
                var fieldValue = $("#" + field).val();

                param[field] = fieldValue;
            }
        });
    }

    // 初始化报表表格
    var dg = $('#dg').datagrid({
        url: queryURL,
        queryParams: param,
        singleSelect: true,
        rownumbers:true,
        striped: true,
        fit: true,
        remoteSort: true,
        pagination:pagination,//显示分页
        pageSize: 500,
        pageList: [500,1000,2000],
        frozenColumns: lockColumn,
        columns: column
    });

    $(".easyui-accordion .panel-header").click();

    /*$(".easyui-accordion").accordion({
        onSelect:function(title, index)
        {
            $(".div-left").scrollTop(10);
             if( $(".div-left").scrollTop()>0 ){
                 // 出现滚动条
                 $(".easyui-accordion .panel-header").css({"width":"88%"});
                 //$(".easyui-accordion").css({"width":"98%"})
             }else{
                 无滚动条
                 $(".easyui-accordion .panel-header").css({"width":"100%"});
                 //$(".easyui-accordion").css({"width":"100%"})
             }
        }
    });*/
});

var showRptInfo = {

    /**
     * 根据选择的个计、万计重置查询条件的单位
     */
    resetUnit : function () {
        var dynamicFormate = $("#formatType").val();

        if(dynamicFormate != '' && typeof(dynamicFormate) != "undefined") {
            if(dynamicFormate.indexOf("0.") != -1) {
                var nodeLength = dynamicFormate.length - 2;
                var unit = "";
                if(nodeLength == 1) {
                    unit = "十";
                } else if(nodeLength == 2) {
                    unit = "百";
                } else if(nodeLength == 3) {
                    unit = "千";
                } else if(nodeLength == 4) {
                    unit = "万";
                }
                $("span[name='formatType']").text(unit);
            } else {
                $("span[name='formatType']").text("");
            }
        }
    },
    /**
     * 查询报表数据(普通报表)
     */
    query : function () {
        $("#queryFlag").val("1");

        // 报表ID
        var rptId = $('#rptId').val();

        // 报表查询列信息
        var conditionCol = $("#conditionCol").val();
        var condition = eval('(' + conditionCol + ')');
        var errorFlag = false;
        var errorMsg = "";

        // 报表初始化查询条件
        var initCondition = $("#initCondition").val();
        var conditionJson = eval('(' + initCondition + ')');

        // 查询参数
        var param = {};

        // 获取初始化参数
        $.each(conditionJson, function(index, content){
         var paramName = content.paramName;
         var paramValue = content.paramValue;
         param[paramName] = paramValue;
         });

        // 获取查询条件的值
        $.each(condition, function(index, content){
            var field = content.aliasField;
            var isNeed = content.isNeed;
            var conditionType = content.conditionType;
            var name = content.name;
            var aliasName = content.aliasName;
            if(!isEmpty(aliasName)) {
                name = aliasName
            }
            if(conditionType == '4') {  // 如果查询类型为日期区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '') {
                    errorMsg = "起始时间不能为空";
                    errorFlag = true;
                    return;
                }
                if(isNeed == '1' && valueEnd == '') {
                    errorMsg = "结束时间不能为空";
                    errorFlag = true;
                    return;
                }

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else if(conditionType == '5') {  // 如果查询类型为树
                var hidField = "hid_" + field;
                var fieldValue = $("#" + hidField).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '\'\'') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }
                param[hidField] = fieldValue;
            } else if (conditionType == '6') {  // 如果查询类型为值区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '' && valueEnd == '') {
                    errorMsg = name + "区间不能为空";
                    errorFlag = true;
                    return;
                }

                // 值区间输入值必须是数字，如果不是数字，给出提示
                var reg = /^(\-|\+)?\d+(\.\d+)?$/;
                //var reg =  /^[0-9]+.?[0-9]*$/;
                if(valueStart != '') {
                    if (!reg.test(valueStart)) {
                        errorMsg = name + "区间开始值请输入数字";
                        errorFlag = true;
                        return;
                    }
                }
                if(valueEnd != '') {
                    if (!reg.test(valueEnd)) {
                        errorMsg = name + "区间结束值请输入数字";
                        errorFlag = true;
                        return;
                    }
                }

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else if(conditionType == '7') {  // 如果查询类型多选下拉框
                var multiSelect = $("#" + field).prev().find("div[class='fs-option selected']");
                var selectEle = multiSelect.length;  // 选中的元素个数

                if(isNeed == '1') {
                    if(selectEle == 0) {
                        errorMsg = name + "不能为空";
                        errorFlag = true;
                        return;
                    }
                }

                var fieldValue = $("#" + field).val();
                param[field] = fieldValue;
            } else {
                var fieldValue = $("#" + field).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }

                param[field] = fieldValue;
            }
        });

        if(errorFlag) {
            //alert(errorMsg);
            $.messager.alert("错误",errorMsg, "error");
            return;
        }

        param.rptId  = rptId;
        var dynamicFormate = $("#formatType").val();

        /*if(dynamicFormate != '' && typeof(dynamicFormate) != "undefined") {
            if(dynamicFormate.indexOf("0.") != -1) {
                var nodeLength = dynamicFormate.length - 2;
                var unit = "";
                if(nodeLength == 1) {
                    unit = "十";
                } else if(nodeLength == 2) {
                    unit = "百";
                } else if(nodeLength == 3) {
                    unit = "千";
                } else if(nodeLength == 4) {
                    unit = "万";
                }
                $("span[name='formatType']").text(unit);
            } else {
                $("span[name='formatType']").text("");
            }
        }*/

        if(dynamicFormate == '' || typeof(dynamicFormate) == "undefined") {
            $('#dg').datagrid({
                url:basePath + "/rptTools/showRpt/queryRptInfo",
                queryParams: param,
                onLoadSuccess: function(data){
                    var status = data.status;
                    if(status == '0') {
                        $.messager.alert("错误",data.msg, "error");
                    } else {
                        var totalCount = data.total;
                        if(totalCount == 0) {
                            $.messager.alert("提示","未查询到数据", "info");
                        }
                    }
                }
            });
        } else {
            $.ajax({
                url:basePath + "/rptTools/showRpt/resetRptHeader",
                type: "POST",
                dataType : "json",
                data:{
                    rptId: rptId,
                    dynamicFormate: dynamicFormate
                },
                success:function(data){  // 重置表头成功后查询报表数据
                    var tableColumn = eval('(' + data.tableHeader + ')');  // 将字符串转换成JSON(列信息)
                    $('#dg').datagrid({
                        url:basePath + "/rptTools/showRpt/queryRptInfo",
                        queryParams: param,
                        columns: tableColumn,
                        onLoadSuccess: function(data){
                            var status = data.status;
                            if(status == '0') {
                                $.messager.alert("错误",data.msg, "error");
                            } else {
                                var totalCount = data.total;
                                if(totalCount == 0) {
                                    $.messager.alert("提示","未查询到数据", "info");
                                }
                            }
                        }
                    });
                }
            });
        }
    },
    /**
     * 根据指标、维度查询报表数据(分析型报表)
     */
    analysisQuery : function () {
        $("#queryFlag").val("1");

        // 报表ID
        var rptId = $('#rptId').val();

        // 报表查询列信息
        var conditionCol = $("#conditionCol").val();
        var condition = eval('(' + conditionCol + ')');
        var errorFlag = false;
        var errorMsg = "";

        // 报表初始化查询条件
        var initCondition = $("#initCondition").val();
        var conditionJson = eval('(' + initCondition + ')');

        // 查询参数
        var param = {};

        // 获取初始化参数
        $.each(conditionJson, function(index, content){
             var paramName = content.paramName;
             var paramValue = content.paramValue;
             param[paramName] = paramValue;
         });

        $.each(condition, function(index, content){
            var field = content.aliasField;
            var isNeed = content.isNeed;
            var conditionType = content.conditionType;
            var name = content.name;
            var aliasName = content.aliasName;
            if(!isEmpty(aliasName)) {
                name = aliasName
            }
            if(conditionType == '4') {  // 如果查询类型为日期区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '') {
                    errorMsg = "起始时间不能为空";
                    errorFlag = true;
                    return;
                }
                if(isNeed == '1' && valueEnd == '') {
                    errorMsg = "结束时间不能为空";
                    errorFlag = true;
                    return;
                }

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else if(conditionType == '5') {  // 如果查询类型为树
                var hidField = "hid_" + field;
                var fieldValue = $("#" + hidField).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '\'\'') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }
                param[hidField] = fieldValue;
            } else if (conditionType == '6') {  // 如果查询类型为值区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '' && valueEnd == '') {
                    errorMsg = name + "区间不能为空";
                    errorFlag = true;
                    return;
                }

                // 值区间输入值必须是数字，如果不是数字，给出提示
                var reg = /^(\-|\+)?\d+(\.\d+)?$/;
                //var reg =  /^[0-9]+.?[0-9]*$/;
                if(valueStart != '') {
                    if (!reg.test(valueStart)) {
                        errorMsg = name + "区间开始值请输入数字";
                        errorFlag = true;
                        return;
                    }
                }
                if(valueEnd != '') {
                    if (!reg.test(valueEnd)) {
                        errorMsg = name + "区间结束值请输入数字"   ;
                        errorFlag = true;
                        return;
                    }
                }

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else if(conditionType == '7') {  // 如果查询类型多选下拉框
                var multiSelect = $("#" + field).prev().find("div[class='fs-option selected']");
                var selectEle = multiSelect.length;  // 选中的元素个数

                if(isNeed == '1') {
                    if(selectEle == 0) {
                        errorMsg = name + "不能为空";
                        errorFlag = true;
                        return;
                    }
                }

                var fieldValue = $("#" + field).val();
                param[field] = fieldValue;
            } else {
                var fieldValue = $("#" + field).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }

                param[field] = fieldValue;
            }
        });

        if(errorFlag) {
            //alert(errorMsg);
            $.messager.alert("错误",errorMsg, "error");
            return;
        }

        // 获取选中的指标
        var idx_array=new Array();
        $('input[name="rptIdx"]:checked').each(function(){
            idx_array.push($(this).val());//向数组中添加元素
        });
        var rptIdx=idx_array.join(',');//将数组元素连接起来以构建一个字符串

        // 获取选中的维度
        var dim_array=new Array();
        $('input[name="rptDim"]:checked').each(function(){
            dim_array.push($(this).val());//向数组中添加元素
        });
        var rptDim=dim_array.join(',');//将数组元素连接起来以构建一个字符串
        param.rptIdx = rptIdx;
        param.rptDim = rptDim;
        param.rptId  = rptId;

        var idxNum = $('input[name="rptIdx"]').length;
        var dimLen = $('input[name="rptDim"]').length;
        var dimNum = dim_array.length;
        var dynamicFormate = $("#formatType").val();

        /*if(dynamicFormate != '' && typeof(dynamicFormate) != "undefined") {
            if(dynamicFormate.indexOf("0.") != -1) {
                var nodeLength = dynamicFormate.length - 2;
                var unit = "";
                if(nodeLength == 1) {
                    unit = "十";
                } else if(nodeLength == 2) {
                    unit = "百";
                } else if(nodeLength == 3) {
                    unit = "千";
                } else if(nodeLength == 4) {
                    unit = "万";
                }
                $("span[name='formatType']").text(unit);
            } else {
                $("span[name='formatType']").text("");
            }
        }*/

        if((idx_array.length == 0 || idxNum == idx_array.length) && (dimNum == dimLen) && dynamicFormate == '') {  // 如果指标全选或全不选，则默认查询所有指标信息
            var allColumn = eval('(' + columns + ')');  // 将字符串转换成JSON(列信息)
            $('#dg').datagrid({
                url:basePath + "/rptTools/showRpt/queryRptInfo",
                queryParams: param,
                columns: allColumn,
                onLoadSuccess: function(data){
                    var status = data.status;
                    if(status == '0') {
                        $.messager.alert("错误",data.msg, "error");
                    } else {
                        var totalCount = data.total;
                        if(totalCount == 0) {
                            $.messager.alert("提示","未查询到数据", "info");
                        }
                    }
                }
            });
        } else {  // 根据选择的指标重置表头信息
            $.ajax({
                url:basePath + "/rptTools/showRpt/resetRptHeader",
                type: "POST",
                dataType : "json",
                data:{
                    rptId: rptId,
                    rptIdx: rptIdx,
                    rptDim: rptDim,
                    dynamicFormate: dynamicFormate
                },
                success:function(data){  // 重置表头成功后查询报表数据
                    var tableColumn = eval('(' + data.tableHeader + ')');  // 将字符串转换成JSON(列信息)
                    $('#dg').datagrid({
                        url:basePath + "/rptTools/showRpt/queryRptInfo",
                        queryParams: param,
                        columns: tableColumn,
                        onLoadSuccess: function(data){
                            var status = data.status;
                            if(status == '0') {
                                $.messager.alert("错误",data.msg, "error");
                            } else {
                                var totalCount = data.total;
                                if(totalCount == 0) {
                                    $.messager.alert("提示","未查询到数据", "info");
                                }
                            }
                        }
                    });
                    $(".multiSelect").each(function(){
                        $(this).css("display","none")
                    });
                }
            });
        }
    },
    /**
     * 展示报表导出Excel
     */
    downLoadExcel : function() {
        $("#downloadform").remove();
        // 报表ID
        var rptId = $('#rptId').val();

        var form = $("<form>");//定义一个form表单
        form.attr("id", "downloadform");
        form.attr("style", "display:none");
        form.attr("target", "");
        form.attr("method", "post");
        form.attr("action", basePath + "/rptTools/showRpt/downLoadExcel");
        var input = $("<input>");
        input.attr("type", "hidden");
        input.attr("name", "rptId");
        input.attr("id", "rptId");
        input.attr("value", rptId);
        form.append(input);


        // 报表查询列信息
        var conditionCol = $("#conditionCol").val();
        var condition = eval('(' + conditionCol + ')');
        var errorFlag = false;
        var errorMsg = "";
        var conditionCount = 0;

        // 报表初始化查询条件
        var initCondition = $("#initCondition").val();
        var conditionJson = eval('(' + initCondition + ')');

        // 查询参数
        var param = {};


        // 获取查询条件的值
        var condition_array=new Array();
        var field_array=new Array();
        $.each(condition, function(index, content){
            conditionCount ++;

            var field = content.aliasField;
            var isNeed = content.isNeed;
            var conditionType = content.conditionType;
            var name = content.name;
            var aliasName = content.aliasName;
            if(!isEmpty(aliasName)) {
                name = aliasName
            }
            var exists = $.inArray(field, field_array);
            if(conditionType == '4' && exists == -1) {  // 如果查询类型为日期区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '') {
                    errorMsg = "起始时间不能为空";
                    errorFlag = true;
                    return;
                }
                if(isNeed == '1' && valueEnd == '') {
                    errorMsg = "结束时间不能为空";
                    errorFlag = true;
                    return;
                }

                var startInput = $("<input>");
                startInput.attr("type", "hidden");
                startInput.attr("name", fieldStart);
                startInput.attr("id", fieldStart);
                startInput.attr("value", valueStart);
                form.append(startInput);

                var endInput = $("<input>");
                endInput.attr("type", "hidden");
                endInput.attr("name", fieldEnd);
                endInput.attr("id", fieldEnd);
                endInput.attr("value", valueEnd);
                form.append(endInput);

                condition_array.push(fieldStart);
                condition_array.push(fieldEnd);
                field_array.push(field);
            } else if(conditionType == '5' && exists == -1) {  // 如果查询类型为树
                var hidField = "hid_" + field;
                var fieldValue = $("#" + hidField).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '\'\'') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }

                var treeInput = $("<input>");
                treeInput.attr("type", "hidden");
                treeInput.attr("name", hidField);
                treeInput.attr("id", hidField);
                treeInput.attr("value", fieldValue);
                form.append(treeInput);

                condition_array.push(hidField);
                field_array.push(field);
            } else if (conditionType == '6' && exists == -1) {  // 如果查询类型为值区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '' && valueEnd == '') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }

                // 值区间输入值必须是数字，如果不是数字，给出提示
                var reg = /^(\-|\+)?\d+(\.\d+)?$/;
                //var reg =  /^[0-9]+.?[0-9]*$/;
                if(valueStart != '') {
                    if (!reg.test(valueStart)) {
                        errorMsg = name + "区间开始值请输入数字";
                        errorFlag = true;
                        return;
                    }
                }
                if(valueEnd != '') {
                    if (!reg.test(valueEnd)) {
                        errorMsg = name + "区间结束值请输入数字"   ;
                        errorFlag = true;
                        return;
                    }
                }

                var startInput = $("<input>");
                startInput.attr("type", "hidden");
                startInput.attr("name", fieldStart);
                startInput.attr("id", fieldStart);
                startInput.attr("value", valueStart);
                form.append(startInput);

                var endInput = $("<input>");
                endInput.attr("type", "hidden");
                endInput.attr("name", fieldEnd);
                endInput.attr("id", fieldEnd);
                endInput.attr("value", valueEnd);
                form.append(endInput);

                condition_array.push(fieldStart);
                condition_array.push(fieldEnd);
                field_array.push(field);
            } else {
                if(exists == -1) {
                    var fieldValue = $("#" + field).val();

                    // 如果查询列条件必输，给出提示
                    if(isNeed == '1' && fieldValue == '') {
                        errorMsg = name + "不能为空";
                        errorFlag = true;
                        return;
                    }
                    if(conditionType == '7') {  // 多选下拉框
                        var multiSelect = $("#" + field).prev().find("div[class='fs-option selected']");
                        var selectEle = multiSelect.length;  // 选中的元素个数
                        if(isNeed == '1') {
                            if(selectEle == 0) {
                                errorMsg = name + "不能为空";
                                errorFlag = true;
                                return;
                            }
                        }
                        fieldValue = $("#" + field).val();
                        if(fieldValue != '' && fieldValue != "undefined"  && fieldValue != null) {
                            var selectValue = '';
                            var selectLen = fieldValue.length;
                            if(selectLen > 1) {
                                $.each(fieldValue,function (i, value){
                                    selectValue = selectValue + "\'" + value + "\',";
                                });
                                selectValue = selectValue.substr(0,selectValue.lastIndexOf(","));
                            } else {
                                selectValue = fieldValue;
                            }
                            var paramInput = $("<input>");
                            paramInput.attr("type", "hidden");
                            paramInput.attr("name", field);
                            paramInput.attr("id", field);
                            paramInput.attr("value", selectValue);
                            form.append(paramInput);
                        }
                    } else {
                        var paramInput = $("<input>");
                        paramInput.attr("type", "hidden");
                        paramInput.attr("name", field);
                        paramInput.attr("id", field);
                        paramInput.attr("value", fieldValue);
                        form.append(paramInput);
                    }

                    condition_array.push(field);
                    field_array.push(field);
                }
            }
        });

        if(errorFlag) {
            alert(errorMsg);
            return;
        }

        // 获取初始化查询条件
        $.each(conditionJson, function(index, content){
            var paramName = content.paramName;
            var paramValue = content.paramValue;

            var exists = $.inArray(paramName, condition_array);
            if(exists == -1) {
                var paramInput = $("<input>");
                paramInput.attr("type", "hidden");
                paramInput.attr("name", paramName);
                paramInput.attr("id", paramName);
                paramInput.attr("value", paramValue);
                form.append(paramInput);
            }
        });

        $("body").append(form);//将表单放置在web中

        form.attr('target', '_blank');
        form.submit();//表单提交
    },
    /**
     * 分析报表导出Excel
     */
    analysisExcelDownLoad : function () {

        $("#downloadform").remove();
        // 报表ID
        var rptId = $('#rptId').val();

        var form = $("<form>");//定义一个form表单
        form.attr("id", "downloadform");
        form.attr("style", "display:none");
        form.attr("target", "");
        form.attr("method", "post");
        form.attr("action", basePath + "/rptTools/showRpt/downLoadExcel");
        var input = $("<input>");
        input.attr("type", "hidden");
        input.attr("name", "rptId");
        input.attr("id", "rptId");
        input.attr("value", rptId);
        form.append(input);

        // 报表查询列信息
        var conditionCol = $("#conditionCol").val();
        var condition = eval('(' + conditionCol + ')');
        var errorFlag = false;
        var errorMsg = "";
        var conditionCount = 0;

        // 报表初始化查询条件
        var initCondition = $("#initCondition").val();
        var conditionJson = eval('(' + initCondition + ')');

        // 查询参数
        var condition_array=new Array();
        var field_array=new Array();
        $.each(condition, function(index, content){
            conditionCount ++;

            var field = content.aliasField;
            var isNeed = content.isNeed;
            var conditionType = content.conditionType;
            var name = content.name;
            var aliasName = content.aliasName;
            if(!isEmpty(aliasName)) {
                name = aliasName
            }
            var exists = $.inArray(field, field_array);
            if(conditionType == '4' && exists == -1) {  // 如果查询类型为日期区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '') {
                    errorMsg = "起始时间不能为空";
                    errorFlag = true;
                    return;
                }
                if(isNeed == '1' && valueEnd == '') {
                    errorMsg = "结束时间不能为空";
                    errorFlag = true;
                    return;
                }

                var startInput = $("<input>");
                startInput.attr("type", "hidden");
                startInput.attr("name", fieldStart);
                startInput.attr("id", fieldStart);
                startInput.attr("value", valueStart);
                form.append(startInput);

                var endInput = $("<input>");
                endInput.attr("type", "hidden");
                endInput.attr("name", fieldEnd);
                endInput.attr("id", fieldEnd);
                endInput.attr("value", valueEnd);
                form.append(endInput);

                condition_array.push(fieldStart);
                condition_array.push(fieldEnd);
                field_array.push(field);
            } else if(conditionType == '5' && exists == -1) {  // 如果查询类型为树
                var hidField = "hid_" + field;
                var fieldValue = $("#" + hidField).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '\'\'') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }

                var treeInput = $("<input>");
                treeInput.attr("type", "hidden");
                treeInput.attr("name", hidField);
                treeInput.attr("id", hidField);
                treeInput.attr("value", fieldValue);
                form.append(treeInput);

                condition_array.push(hidField);
                field_array.push(field);
            } else if (conditionType == '6' && exists == -1) {  // 如果查询类型为值区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '' && valueEnd == '') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }

                // 值区间输入值必须是数字，如果不是数字，给出提示
                var reg = /^(\-|\+)?\d+(\.\d+)?$/;
                //var reg =  /^[0-9]+.?[0-9]*$/;
                if(valueStart != '') {
                    if (!reg.test(valueStart)) {
                        errorMsg = name + "区间开始值请输入数字";
                        errorFlag = true;
                        return;
                    }
                }
                if(valueEnd != '') {
                    if (!reg.test(valueEnd)) {
                        errorMsg = name + "区间结束值请输入数字"   ;
                        errorFlag = true;
                        return;
                    }
                }

                var startInput = $("<input>");
                startInput.attr("type", "hidden");
                startInput.attr("name", fieldStart);
                startInput.attr("id", fieldStart);
                startInput.attr("value", valueStart);
                form.append(startInput);

                var endInput = $("<input>");
                endInput.attr("type", "hidden");
                endInput.attr("name", fieldEnd);
                endInput.attr("id", fieldEnd);
                endInput.attr("value", valueEnd);
                form.append(endInput);

                condition_array.push(fieldStart);
                condition_array.push(fieldEnd);
                field_array.push(field);
            } else {
                if(exists == -1) {
                    var fieldValue = $("#" + field).val();

                    // 如果查询列条件必输，给出提示
                    if(isNeed == '1' && fieldValue == '') {
                        errorMsg = name + "不能为空";
                        errorFlag = true;
                        return;
                    }

                    if(conditionType == '7') {
                        var multiSelect = $("#" + field).prev().find("div[class='fs-option selected']");
                        var selectEle = multiSelect.length;  // 选中的元素个数
                        if(isNeed == '1') {
                            if(selectEle == 0) {
                                errorMsg = name + "不能为空";
                                errorFlag = true;
                                return;
                            }
                        }

                        fieldValue = $("#" + field).val();
                        if(fieldValue != '' && fieldValue != "undefined"  && fieldValue != null) {
                            var selectValue = '';
                            var selectLen = fieldValue.length;

                            if(selectLen > 1) {
                                $.each(fieldValue,function (i, value){
                                    selectValue = selectValue + "\'" + value + "\',";
                                });
                                selectValue = selectValue.substr(0,selectValue.lastIndexOf(","));
                            } else {
                                selectValue = fieldValue;
                            }

                            var paramInput = $("<input>");
                            paramInput.attr("type", "hidden");
                            paramInput.attr("name", field);
                            paramInput.attr("id", field);
                            paramInput.attr("value", selectValue);
                            form.append(paramInput);
                        }
                    } else {
                        var paramInput = $("<input>");
                        paramInput.attr("type", "hidden");
                        paramInput.attr("name", field);
                        paramInput.attr("id", field);
                        paramInput.attr("value", fieldValue);
                        form.append(paramInput);
                    }

                    condition_array.push(field);
                    field_array.push(field);
                }
            }
        });

        if(errorFlag) {
            alert(errorMsg);
            return;
        }

        // 获取初始化查询条件
        $.each(conditionJson, function(index, content){
            var paramName = content.paramName;
            var paramValue = content.paramValue;

            var exists = $.inArray(paramName, condition_array);
            if(exists == -1) {
                var paramInput = $("<input>");
                paramInput.attr("type", "hidden");
                paramInput.attr("name", paramName);
                paramInput.attr("id", paramName);
                paramInput.attr("value", paramValue);
                form.append(paramInput);
            }
        });

        // 获取选中的指标
        var idx_array=new Array();
        $('input[name="rptIdx"]:checked').each(function(){
            idx_array.push($(this).val());//向数组中添加元素
        });
        var rptIdx=idx_array.join(',');//将数组元素连接起来以构建一个字符串

        // 获取选中的维度
        var dim_array=new Array();
        $('input[name="rptDim"]:checked').each(function(){
            dim_array.push($(this).val());//向数组中添加元素
        });
        var rptDim=dim_array.join(',');//将数组元素连接起来以构建一个字符串

        var idxInput = $("<input>");
        idxInput.attr("type", "hidden");
        idxInput.attr("name", "rptIdx");
        idxInput.attr("id", "rptIdx");
        idxInput.attr("value", rptIdx);
        form.append(idxInput);

        var dimInput = $("<input>");
        dimInput.attr("type", "hidden");
        dimInput.attr("name", "rptDim");
        dimInput.attr("id", "rptDim");
        dimInput.attr("value", rptDim);
        form.append(dimInput);

        $("body").append(form);//将表单放置在web中
        form.attr('target', '_blank');
        form.submit();//表单提交
    },
    /**
     * 离线下载
     */
    offLineDownLoad: function (rptName) {

        // 报表ID
        var rptId = $('#rptId').val();
        // 报表接入系统访问报表的用户ID
        var userId = $("#userId").val();
        // 报表接入系统访问报表的系统编码
        var itemCode = $("#itemCode").val();

        // 报表查询列信息
        var conditionCol = $("#conditionCol").val();
        var condition = eval('(' + conditionCol + ')');
        var errorFlag = false;
        var errorMsg = "";

        // 报表初始化查询条件
        var initCondition = $("#initCondition").val();
        var conditionJson = eval('(' + initCondition + ')');

        // 查询参数
        var param = {};

        // 获取初始化参数
        $.each(conditionJson, function(index, content){
            var paramName = content.paramName;
            var paramValue = content.paramValue;
            param[paramName] = paramValue;
        });

        // 获取查询条件的值
        $.each(condition, function(index, content){
            var field = content.aliasField;
            var isNeed = content.isNeed;
            var conditionType = content.conditionType;
            var name = content.name;
            var aliasName = content.aliasName;
            if(!isEmpty(aliasName)) {
                name = aliasName
            }
            if(conditionType == '4') {  // 如果查询类型为日期区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '') {
                    errorMsg = "起始时间不能为空";
                    errorFlag = true;
                    return;
                }
                if(isNeed == '1' && valueEnd == '') {
                    errorMsg = "结束时间不能为空";
                    errorFlag = true;
                    return;
                }

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else if(conditionType == '5') {  // 如果查询类型为树
                var hidField = "hid_" + field;
                var fieldValue = $("#" + hidField).val();
                var treeField = field + "Id";
                var fieldName = $("#" + field + "Id").val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '\'\'') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }
                param[hidField] = fieldValue;
                param[treeField] = fieldName;
            } else if (conditionType == '6') {  // 如果查询类型为值区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '' && valueEnd == '') {
                    errorMsg = name + "区间不能为空";
                    errorFlag = true;
                    return;
                }

                // 值区间输入值必须是数字，如果不是数字，给出提示
                var reg = /^(\-|\+)?\d+(\.\d+)?$/;
                //var reg =  /^[0-9]+.?[0-9]*$/;
                if(valueStart != '') {
                    if (!reg.test(valueStart)) {
                        errorMsg = name + "区间开始值请输入数字";
                        errorFlag = true;
                        return;
                    }
                }
                if(valueEnd != '') {
                    if (!reg.test(valueEnd)) {
                        errorMsg = name + "区间结束值请输入数字";
                        errorFlag = true;
                        return;
                    }
                }

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else {
                var fieldValue = $("#" + field).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }

                param[field] = fieldValue;
            }
        });

        if(errorFlag) {
            alert(errorMsg);
            return;
        }

        param.rptId = rptId;
        param.userId = userId;
        param.itemCode = itemCode;

        $.messager.prompt('提示', '请输入离线下载的文件名', function(rptName){
            if(rptName) {
                $.messager.progress({
                    title:'离线下载',
                    msg:'正在创建离线下载任务...',
                    interval: 500
                });
                param.aliasRptName = rptName;
                $.ajax({
                    url: basePath + "/rptTools/showRpt/offLineDownLoad",
                    type: "POST",
                    dataType: "json",
                    data: param,
                    success: function (data) {
                        $.messager.progress('close');
                        var status = data.status;
                        var msg = data.msg;
                        if (status == '1') {
                            $.messager.alert("提示","离线下载成功，请转至[基础管理-我的报表-离线下载列表]查看");
                        } else {
                            $.messager.alert("提示","离线下载失败:" + msg);
                        }
                    }
                });
            } else if(rptName == "") {
                $.messager.alert("提示","文件名不能为空");
            } else {

            }
        });
        $(".messager-input").val(rptName);
    },
    /**
     * 分析报表离线下载
     */
    analysisOffLineDownLoad: function (rptName) {

        // 报表ID
        var rptId = $('#rptId').val();
        // 报表接入系统访问报表的用户ID
        var userId = $("#userId").val();
        // 报表接入系统访问报表的系统编码
        var itemCode = $("#itemCode").val();

        // 报表查询列信息
        var conditionCol = $("#conditionCol").val();
        var condition = eval('(' + conditionCol + ')');
        var errorFlag = false;
        var errorMsg = "";

        // 报表初始化查询条件
        var initCondition = $("#initCondition").val();
        var conditionJson = eval('(' + initCondition + ')');

        // 查询参数
        var param = {};

        // 获取初始化参数
        $.each(conditionJson, function(index, content){
            var paramName = content.paramName;
            var paramValue = content.paramValue;
            param[paramName] = paramValue;
        });

        $.each(condition, function(index, content){
            var field = content.aliasField;
            var isNeed = content.isNeed;
            var conditionType = content.conditionType;
            var name = content.name;
            var aliasName = content.aliasName;
            if(!isEmpty(aliasName)) {
                name = aliasName
            }
            if(conditionType == '4') {  // 如果查询类型为日期区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '') {
                    errorMsg = "起始时间不能为空";
                    errorFlag = true;
                    return;
                }
                if(isNeed == '1' && valueEnd == '') {
                    errorMsg = "结束时间不能为空";
                    errorFlag = true;
                    return;
                }

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else if(conditionType == '5') {  // 如果查询类型为树
                var hidField = "hid_" + field;
                var fieldValue = $("#" + hidField).val();
                var treeField = field + "Id";
                var fieldName = $("#" + field + "Id").val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '\'\'') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }
                param[hidField] = fieldValue;
                param[treeField] = fieldName;
            } else if (conditionType == '6') {  // 如果查询类型为值区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '' && valueEnd == '') {
                    errorMsg = name + "区间不能为空";
                    errorFlag = true;
                    return;
                }

                // 值区间输入值必须是数字，如果不是数字，给出提示
                var reg = /^(\-|\+)?\d+(\.\d+)?$/;
                //var reg =  /^[0-9]+.?[0-9]*$/;
                if(valueStart != '') {
                    if (!reg.test(valueStart)) {
                        errorMsg = name + "区间开始值请输入数字";
                        errorFlag = true;
                        return;
                    }
                }
                if(valueEnd != '') {
                    if (!reg.test(valueEnd)) {
                        errorMsg = name + "区间结束值请输入数字"   ;
                        errorFlag = true;
                        return;
                    }
                }

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else {
                var fieldValue = $("#" + field).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }

                param[field] = fieldValue;
            }
        });

        if(errorFlag) {
            alert(errorMsg);
            return;
        }

        // 获取选中的指标
        var idx_array=new Array();
        $('input[name="rptIdx"]:checked').each(function(){
            idx_array.push($(this).val());//向数组中添加元素
        });
        var rptIdx=idx_array.join(',');//将数组元素连接起来以构建一个字符串

        // 获取选中的维度
        var dim_array=new Array();
        $('input[name="rptDim"]:checked').each(function(){
            dim_array.push($(this).val());//向数组中添加元素
        });
        var rptDim=dim_array.join(',');//将数组元素连接起来以构建一个字符串
        param.rptIdx = rptIdx;
        param.rptDim = rptDim;
        param.rptId = rptId;
        param.userId = userId;
        param.itemCode = itemCode;

        $.messager.prompt('提示', '请输入离线下载的文件名', function(rptName) {
            if(rptName) {
                $.messager.progress({
                    title:'离线下载',
                    msg:'正在创建离线下载任务...',
                    interval: 500
                });
                param.aliasRptName = rptName;
                $.ajax({
                    url: basePath + "/rptTools/showRpt/offLineDownLoad",
                    type: "POST",
                    dataType: "json",
                    data: param,
                    success: function (data) {
                        $.messager.progress('close');
                        var status = data.status;
                        var msg = data.msg;
                        if (status == '1') {
                            $.messager.alert("提示","离线下载成功，请转至[基础管理-我的报表-离线下载列表]查看");
                        } else {
                            $.messager.alert("提示","离线下载失败:" + msg);
                        }
                    }
                });
            } else if (rptName == "") {
                $.messager.alert('提示','文件名不能为空!');
                //alert("文件名不能为空");
            } else {
            }
        });
        $(".messager-input").val(rptName);
    },
    /**
     * 分析报表离线下载
     */
    analysisOffLineDownLoad: function (rptName) {

        // 报表ID
        var rptId = $('#rptId').val();
        // 报表接入系统访问报表的用户ID
        var userId = $("#userId").val();
        // 报表接入系统访问报表的系统编码
        var itemCode = $("#itemCode").val();

        // 报表查询列信息
        var conditionCol = $("#conditionCol").val();
        var condition = eval('(' + conditionCol + ')');
        var errorFlag = false;
        var errorMsg = "";

        // 报表初始化查询条件
        var initCondition = $("#initCondition").val();
        var conditionJson = eval('(' + initCondition + ')');

        // 查询参数
        var param = {};

        // 获取初始化参数
        $.each(conditionJson, function(index, content){
            var paramName = content.paramName;
            var paramValue = content.paramValue;
            param[paramName] = paramValue;
        });

        $.each(condition, function(index, content){
            var field = content.aliasField;
            var isNeed = content.isNeed;
            var conditionType = content.conditionType;
            var name = content.name;
            var aliasName = content.aliasName;
            if(!isEmpty(aliasName)) {
                name = aliasName
            }
            if(conditionType == '4') {  // 如果查询类型为日期区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '') {
                    errorMsg = "起始时间不能为空";
                    errorFlag = true;
                    return;
                }
                if(isNeed == '1' && valueEnd == '') {
                    errorMsg = "结束时间不能为空";
                    errorFlag = true;
                    return;
                }

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else if(conditionType == '5') {  // 如果查询类型为树
                var hidField = "hid_" + field;
                var fieldValue = $("#" + hidField).val();
                var treeField = field + "Id";
                var fieldName = $("#" + field + "Id").val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '\'\'') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }
                param[hidField] = fieldValue;
                param[treeField] = fieldName;
            } else if (conditionType == '6') {  // 如果查询类型为值区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && valueStart == '' && valueEnd == '') {
                    errorMsg = name + "区间不能为空";
                    errorFlag = true;
                    return;
                }

                // 值区间输入值必须是数字，如果不是数字，给出提示
                var reg = /^(\-|\+)?\d+(\.\d+)?$/;
                //var reg =  /^[0-9]+.?[0-9]*$/;
                if(valueStart != '') {
                    if (!reg.test(valueStart)) {
                        errorMsg = name + "区间开始值请输入数字";
                        errorFlag = true;
                        return;
                    }
                }
                if(valueEnd != '') {
                    if (!reg.test(valueEnd)) {
                        errorMsg = name + "区间结束值请输入数字"   ;
                        errorFlag = true;
                        return;
                    }
                }

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else {
                var fieldValue = $("#" + field).val();

                // 如果查询列条件必输，给出提示
                if(isNeed == '1' && fieldValue == '') {
                    errorMsg = name + "不能为空";
                    errorFlag = true;
                    return;
                }

                param[field] = fieldValue;
            }
        });

        if(errorFlag) {
            alert(errorMsg);
            return;
        }

        // 获取选中的指标
        var idx_array=new Array();
        $('input[name="rptIdx"]:checked').each(function(){
            idx_array.push($(this).val());//向数组中添加元素
        });
        var rptIdx=idx_array.join(',');//将数组元素连接起来以构建一个字符串

        // 获取选中的维度
        var dim_array=new Array();
        $('input[name="rptDim"]:checked').each(function(){
            dim_array.push($(this).val());//向数组中添加元素
        });
        var rptDim=dim_array.join(',');//将数组元素连接起来以构建一个字符串
        param.rptIdx = rptIdx;
        param.rptDim = rptDim;
        param.rptId = rptId;
        param.userId = userId;
        param.itemCode = itemCode;

        $.messager.prompt('提示', '请输入离线下载的文件名', function(rptName) {
            if(rptName) {
                $.messager.progress({
                    title:'离线下载',
                    msg:'正在创建离线下载任务...',
                    interval: 500
                });
                param.aliasRptName = rptName;
                $.ajax({
                    url: basePath + "/rptTools/showRpt/offLineDownLoad",
                    type: "POST",
                    dataType: "json",
                    data: param,
                    success: function (data) {
                        $.messager.progress('close');
                        var status = data.status;
                        var msg = data.msg;
                        if (status == '1') {
                            $.messager.alert("提示","离线下载成功，请转至[基础管理-我的报表-离线下载列表]查看");
                        } else {
                            $.messager.alert("提示","离线下载失败:" + msg);
                        }
                    }
                });
            } else if (rptName == "") {
                $.messager.alert('提示','文件名不能为空!');
                //alert("文件名不能为空");
            } else {
            }
        });
        $(".messager-input").val(rptName);
    },
    /**
     * 自定义报表
     */
    selfDefine: function (rptName) {

        // 报表ID
        var rptId = $('#rptId').val();
        // 报表接入系统访问报表的用户ID
        var userId = $("#userId").val();
        // 报表接入系统访问报表的系统编码
        var itemCode = $("#itemCode").val();

        // 报表查询列信息
        var conditionCol = $("#conditionCol").val();
        var condition = eval('(' + conditionCol + ')');

        // 报表初始化查询条件
        var initCondition = $("#initCondition").val();
        var conditionJson = eval('(' + initCondition + ')');

        // 查询参数
        var param = {};

        // 获取初始化参数
        $.each(conditionJson, function(index, content){
            var paramName = content.paramName;
            var paramValue = content.paramValue;
            param[paramName] = paramValue;
        });

        // 获取查询条件的值
        $.each(condition, function(index, content){
            var field = content.aliasField;
            var conditionType = content.conditionType;
            if(conditionType == '4') {  // 如果查询类型为日期区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else if(conditionType == '5') {  // 如果查询类型为树
                var hidField = "hid_" + field;
                var fieldValue = $("#" + hidField).val();
                var treeField = field + "Id";
                var fieldName = $("#" + field + "Id").val();

                param[hidField] = fieldValue;
                param[treeField] = fieldName;
            } else if (conditionType == '6') {  // 如果查询类型为值区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else {
                var fieldValue = $("#" + field).val();

                param[field] = fieldValue;
            }
        });

        param.rptId = rptId;
        param.userId = userId;
        param.itemCode = itemCode;
        var rptURL = window.location.href;
        param.rptURL = rptURL;

        $.messager.prompt('提示', '请输入自定义报表名称', function(rptName){
            if(rptName) {
                $.messager.progress({
                    title:'自定义报表',
                    msg:'正在创建自定义报表...',
                    interval: 500
                });
                param.aliasRptName = rptName;
                $.ajax({
                    url: basePath + "/rptTools/showRpt/selfDefine",
                    type: "POST",
                    dataType: "json",
                    data: param,
                    success: function (data) {
                        $.messager.progress('close');
                        var status = data.status;
                        var msg = data.msg;
                        if (status == '1') {
                            $.messager.alert("提示","自定义报表成功，请转至[基础管理-我的报表-自定义报表]查看");
                        } else {
                            $.messager.alert("提示","自定义报表失败:" + msg);
                        }
                    }
                });
            } else if(rptName == "") {
                $.messager.alert("提示","自定义报表名称不能为空");
            } else {

            }
        });
        $(".messager-input").val(rptName);
    },
    /**
     * 分析报表离线下载
     */
    analysisSelfDefine: function (rptName) {

        // 报表ID
        var rptId = $('#rptId').val();
        // 报表接入系统访问报表的用户ID
        var userId = $("#userId").val();
        // 报表接入系统访问报表的系统编码
        var itemCode = $("#itemCode").val();

        // 报表查询列信息
        var conditionCol = $("#conditionCol").val();
        var condition = eval('(' + conditionCol + ')');

        // 报表初始化查询条件
        var initCondition = $("#initCondition").val();
        var conditionJson = eval('(' + initCondition + ')');

        // 查询参数
        var param = {};

        // 获取初始化参数
        $.each(conditionJson, function(index, content){
            var paramName = content.paramName;
            var paramValue = content.paramValue;
            param[paramName] = paramValue;
        });

        $.each(condition, function(index, content){
            var field = content.aliasField;
            var conditionType = content.conditionType;
            if(conditionType == '4') {  // 如果查询类型为日期区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else if(conditionType == '5') {  // 如果查询类型为树
                var hidField = "hid_" + field;
                var fieldValue = $("#" + hidField).val();
                var treeField = field + "Id";
                var fieldName = $("#" + field + "Id").val();

                param[hidField] = fieldValue;
                param[treeField] = fieldName;
            } else if (conditionType == '6') {  // 如果查询类型为值区间
                var fieldStart = field + "_start";
                var fieldEnd = field + "_end";
                var valueStart = $("#" + fieldStart).val();
                var valueEnd = $("#" + fieldEnd).val();

                param[fieldStart] = valueStart;
                param[fieldEnd] = valueEnd;
            } else {
                var fieldValue = $("#" + field).val();

                param[field] = fieldValue;
            }
        });

        // 获取选中的指标
        var idx_array=new Array();
        $('input[name="rptIdx"]:checked').each(function(){
            idx_array.push($(this).val());//向数组中添加元素
        });
        var rptIdx=idx_array.join(',');//将数组元素连接起来以构建一个字符串

        // 获取选中的维度
        var dim_array=new Array();
        $('input[name="rptDim"]:checked').each(function(){
            dim_array.push($(this).val());//向数组中添加元素
        });
        var rptDim=dim_array.join(',');//将数组元素连接起来以构建一个字符串
        param.rptIdx = rptIdx;
        param.rptDim = rptDim;
        param.rptId = rptId;
        param.userId = userId;
        param.itemCode = itemCode;
        var rptURL = window.location.href;
        param.rptURL = rptURL;

        $.messager.prompt('提示', '请输入自定义报表名称', function(rptName) {
            if(rptName) {
                $.messager.progress({
                    title:'自定义报表',
                    msg:'正在创建自定义报表...',
                    interval: 500
                });
                param.aliasRptName = rptName;
                $.ajax({
                    url: basePath + "/rptTools/showRpt/selfDefine",
                    type: "POST",
                    dataType: "json",
                    data: param,
                    success: function (data) {
                        $.messager.progress('close');
                        var status = data.status;
                        var msg = data.msg;
                        if (status == '1') {
                            $.messager.alert("提示","自定义报表成功，请转至[基础管理-我的报表-自定义报表]查看");
                        } else {
                            $.messager.alert("提示","自定义报表失败:" + msg);
                        }
                    }
                });
            } else if (rptName == "") {
                $.messager.alert('提示','自定义报表名称不能为空');
            } else {
            }
        });
        $(".messager-input").val(rptName);
    },
    /**
     * 点击指标全选或全不选所有指标
     */
    selectAllIdx: function () {
        var flag = this.checkIdxSelectState();
        if(flag) {
            $("input[type='checkbox'][name='rptIdx']").each(function(){
                $(this).attr("checked",false)
            });
        } else {
            $("input[type='checkbox'][name='rptIdx']").each(function(){
                this.checked=true;
            });
        }
    },
    checkIdxSelectState : function () {
        var flag = true;
        $("input[type='checkbox'][name='rptIdx']").each(function(){
            if(this.checked) {
                flag = true;
            } else {
                flag = false;
                return flag;
            }
        });
        return flag;
    },
    selectSubIdx : function (obj) {
        var flag = this.checkSubIdxSelectState(obj);
        if(flag) {
            $(obj).next().find("input[type='checkbox'][name='rptIdx']").each(function(){
                $(this).attr("checked",false)
            });
        } else {
            $(obj).next().find("input[type='checkbox'][name='rptIdx']").each(function(){
                this.checked=true;
            });
        }
    },
    checkSubIdxSelectState : function (obj) {
        var flag = true;
        $(obj).next().find("input[type='checkbox'][name='rptIdx']").each(function(){
            if(this.checked) {
                flag = true;
            } else {
                flag = false;
                return flag;
            }
        });
        return flag;
    },
    /**
     * 点击指标全选或全不选所有维度
     */
    selectAllDim: function () {
        var flag = this.checkDimSelectState();
        if(flag) {
            $("input[type='checkbox'][name='rptDim']").each(function(){
                $(this).attr("checked",false)
            });
        } else {
            $("input[type='checkbox'][name='rptDim']").each(function(){
                this.checked=true;
            });
        }
    },
    checkDimSelectState : function () {
        var flag = true;
        $("input[type='checkbox'][name='rptDim']").each(function(){
            if(this.checked) {
                flag = true;
            } else {
                flag = false;
                return flag;
            }
        });
        return flag;
    },
    swithcIdx : function (obj) {
        var imgSrc = obj.src;
        if(imgSrc.match("down")) {
            obj.src = basePath + "/styles/imgs/up.png";
        } else if(imgSrc.match("up")) {
            obj.src = basePath + "/styles/imgs/down.png";
        }
        $(obj).parent().parent().next().slideToggle();
        var event = window.event||arguments[0];
        event.stopPropagation();  // 防止事件冒泡
    },
    foratterDate : function (dateId,cascadeCondition) {
        var dateIds = dateId.split(",");
        var format = $("#dateType").val();
        var formatTxt = $("#dateType").find("option:selected").text();;
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if(month >=1 && month <= 9) {
            month = "0" + month;
        }
        if(strDate >=0 && strDate <= 9) {
            strDate = "0" + strDate;
        }

        for(var i=0;i<dateIds.length;i++){
            var id = dateIds[i];
            $("#"+id).attr("onFocus","WdatePicker({onpicked:function() {},dateFmt:'" + format + "'})");
            if(format == "yyyyMMdd") {
                $("#" + id).val(year + "" + month + "" + strDate);
            } else if(format == "yyyyMM") {
                $("#" + id).val(year + "" + month);
            } else if(format == "yyyy") {
                $("#" + id).val(year);
            }
        }

        if(cascadeCondition != "" && typeof(cascadeCondition) != "undefined") {
            $.each($("#" + cascadeCondition + " option"), function (idx, obj) {
                var cascadeTxt = $(obj).text();
                if(formatTxt == cascadeTxt) {
                    $(obj).prop("selected", true);
                } else {
                    $(obj).prop("selected", false);
                }
            })
        }
    },
    showMore : function (obj) {
        $("#hideCondition").slideToggle(function () {
            if($(this).is(":hidden")) {
                $(obj).text("更多选项");
                $(obj).next().attr("src",basePath + "/styles/imgs/arrow_down.png");
            } else {
                $(obj).text("隐藏选项");
                $(obj).next().attr("src",basePath + "/styles/imgs/arrow_up.png");
            }
        });
    },
    moreOver : function (obj) {
        $(obj).css("color","red");
    },
    moreOut : function (obj) {
        $(obj).css("color","#444");
    },
    isEmpty : function isEmpty(obj) {
    if(typeof obj == "undefined" || obj == null || obj == ""){
        return true;
    }else{
        return false;
    }
}
}
